var prefix="/shiro/";
$(function () {
	valid();
});
$.validator.setDefaults({
    submitHandler: function() {
    	update();
    }
});
function update(){
	var d=getFormJson("signupForm");
	if (!Array.isArray(d.roleIds)) {
		var roleIdArr=[];
		roleIdArr.push(d.roleIds);
		d.roleIds=roleIdArr;
	}
    var config={
			url : prefix+"/update",
			data:d,
	}
	EasyAjax.post_json(config,function(r){
		layer.msg(r.msg);
		if (r.code == 0){
			parent.reLoad();
			var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
			parent.layer.close(index);
		} 
	});
	
}
function valid(){
    var icon = "<i class='fa fa-times-circle'></i>";
    $("#signupForm").validate({
        rules:{
        	route: {
        		 required: true,
                 maxlength: 20,
        	},
        	perm: {
                required: true,
                maxlength: 8,
            },
            isWork: {
                required: true,
            },
            num: {
                required: true,
            },
        },
        messages: {
        	route: {
        		required:icon + "请输资源路径",
        		maxlength:icon + "最多20个字符",
        	},
        	perm: {
        		required:icon + "请输权限类别",
        		maxlength:icon + "最多8个字符",
        	},
        	isWork: {
        		required:icon + "请选择是否启用",
            },
            num: {
        		required:icon + "请输入序号",
            },
        }
    });
}

